package com.apollographql.apollo.api;

import java.util.LinkedHashMap;
import java.util.Map;
import com.kt.Metadata;
import com.kt.Pair;
import com.kt.TuplesKt;
import com.kt.collections.MapsKt;
import com.kt.jvm.functions.Function1;
import com.kt.jvm.internal.DefaultConstructorMarker;
import com.kt.jvm.internal.Intrinsics;
import com.kt.ranges.RangesKt;

@Metadata(bv = {1, 0, 3}, d1 = {"\u0000\"\n\u0002\u0018\u0002\n\u0002\u0010\u0000\n\u0000\n\u0002\u0010$\n\u0002\u0018\u0002\n\u0002\u0018\u0002\n\u0002\b\u0004\n\u0002\u0010\u000e\n\u0002\b\u0005\u0018\u0000 \u000e2\u00020\u0001:\u0001\u000eB\u001d\u0012\u0016\u0010\u0002\u001a\u0012\u0012\u0004\u0012\u00020\u0004\u0012\b\u0012\u0006\u0012\u0002\b\u00030\u00050\u0003¢\u0006\u0002\u0010\u0006J\u001e\u0010\u000b\u001a\b\u0012\u0004\u0012\u0002H\f0\u0005\"\b\b\u0000\u0010\f*\u00020\u00012\u0006\u0010\r\u001a\u00020\u0004R!\u0010\u0002\u001a\u0012\u0012\u0004\u0012\u00020\u0004\u0012\b\u0012\u0006\u0012\u0002\b\u00030\u00050\u0003¢\u0006\b\n\u0000\u001a\u0004\b\u0007\u0010\bR\u001e\u0010\t\u001a\u0012\u0012\u0004\u0012\u00020\n\u0012\b\u0012\u0006\u0012\u0002\b\u00030\u00050\u0003X\u0004¢\u0006\u0002\n\u0000¨\u0006\u000f"}, d2 = {"Lcom/apollographql/apollo/api/ScalarTypeAdapters;", "", "customAdapters", "", "Lcom/apollographql/apollo/api/ScalarType;", "Lcom/apollographql/apollo/api/CustomTypeAdapter;", "(Ljava/util/Map;)V", "getCustomAdapters", "()Ljava/util/Map;", "customTypeAdapters", "", "adapterFor", "T", "scalarType", "Companion", "apollo-api"}, k = 1, mv = {1, 4, 0})
/* compiled from: ScalarTypeAdapters.kt */
public final class ScalarTypeAdapters {
    public static final Companion Companion = new Companion(null);
    public static final ScalarTypeAdapters DEFAULT = new ScalarTypeAdapters(MapsKt.emptyMap());
    private final Map<ScalarType, CustomTypeAdapter<?>> customAdapters;
    private final Map<String, CustomTypeAdapter<?>> customTypeAdapters;

    /* JADX DEBUG: Multi-variable search result rejected for r13v0, resolved type: java.util.Map<com.apollographql.apollo.api.ScalarType, ? extends com.apollographql.apollo.api.CustomTypeAdapter<?>> */
    /* JADX WARN: Multi-variable type inference failed */
    public ScalarTypeAdapters(Map<ScalarType, ? extends CustomTypeAdapter<?>> map) {
        Intrinsics.checkParameterIsNotNull(map, "customAdapters");
        this.customAdapters = (Map<ScalarType, CustomTypeAdapter<?>>) map;
        Map $this$mapKeys$iv = this.customAdapters;
        Map destination$iv$iv = new LinkedHashMap(MapsKt.mapCapacity($this$mapKeys$iv.size()));
        for (Object element$iv$iv$iv : $this$mapKeys$iv.entrySet()) {
            Map.Entry element= (Map.Entry) element$iv$iv$iv;
            destination$iv$iv.put(((ScalarType) element.getKey()).typeName(), element.getValue());
        }
        this.customTypeAdapters = destination$iv$iv;
    }

    public final Map<ScalarType, CustomTypeAdapter<?>> getCustomAdapters() {
        return this.customAdapters;
    }

    public final <T> CustomTypeAdapter<T> adapterFor(ScalarType scalarType) {
        Intrinsics.checkParameterIsNotNull(scalarType, "scalarType");
        CustomTypeAdapter customTypeAdapter = (CustomTypeAdapter<T>) this.customTypeAdapters.get(scalarType.typeName());

        if (customTypeAdapter != null) {
            return (CustomTypeAdapter<T>) customTypeAdapter;
        }
        throw new IllegalArgumentException(("Can't map GraphQL type: `" + scalarType.typeName() + "` to: `" + scalarType.className() + "`. Did you forget to add a custom type adapter?").toString());
    }

    @Metadata(bv = {1, 0, 3}, d1 = {"\u00008\n\u0002\u0018\u0002\n\u0002\u0010\u0000\n\u0002\b\u0002\n\u0002\u0018\u0002\n\u0000\n\u0002\u0010$\n\u0002\u0010\u000e\n\u0002\u0018\u0002\n\u0002\b\u0002\n\u0002\u0010\u0011\n\u0000\n\u0002\u0018\u0002\n\u0002\u0018\u0002\n\u0002\u0018\u0002\n\u0002\b\u0004\b\u0003\u0018\u00002\u00020\u0001B\u0007\b\u0002¢\u0006\u0002\u0010\u0002JX\u0010\t\u001a\u0012\u0012\u0004\u0012\u00020\u0007\u0012\b\u0012\u0006\u0012\u0002\b\u00030\b0\u00062\u0012\u0010\n\u001a\n\u0012\u0006\b\u0001\u0012\u00020\u00070\u000b\"\u00020\u00072%\u0010\f\u001a!\u0012\u0017\u0012\u0015\u0012\u0002\b\u00030\u000e¢\u0006\f\b\u000f\u0012\b\b\u0010\u0012\u0004\b\b(\u0011\u0012\u0004\u0012\u00020\u00010\rH\u0002¢\u0006\u0002\u0010\u0012R\u0010\u0010\u0003\u001a\u00020\u00048\u0006X\u0004¢\u0006\u0002\n\u0000R\u001e\u0010\u0005\u001a\u0012\u0012\u0004\u0012\u00020\u0007\u0012\b\u0012\u0006\u0012\u0002\b\u00030\b0\u0006X\u0004¢\u0006\u0002\n\u0000¨\u0006\u0013"}, d2 = {"Lcom/apollographql/apollo/api/ScalarTypeAdapters$Companion;", "", "()V", "DEFAULT", "Lcom/apollographql/apollo/api/ScalarTypeAdapters;", "DEFAULT_ADAPTERS", "", "", "Lcom/apollographql/apollo/api/CustomTypeAdapter;", "createDefaultScalarTypeAdapter", "classNames", "", "decode", "Lkotlin/Function1;", "Lcom/apollographql/apollo/api/CustomTypeValue;", "Lkotlin/ParameterName;", "name", "value", "([Ljava/lang/String;Lkotlin/jvm/functions/Function1;)Ljava/util/Map;", "apollo-api"}, k = 1, mv = {1, 4, 0})
    /* compiled from: ScalarTypeAdapters.kt */
    public static final class Companion {
        private Companion() {
        }

        public /* synthetic */ Companion(DefaultConstructorMarker $constructor_marker) {
            this();
        }

        /* access modifiers changed from: private */
        /* access modifiers changed from: public */
        private final Map<String, CustomTypeAdapter<?>> createDefaultScalarTypeAdapter(String[] classNames, Function1<? super CustomTypeValue<?>, ? extends Object> function1) {
            ScalarTypeAdapters$Companion$createDefaultScalarTypeAdapter$adapter$1 adapter = new ScalarTypeAdapters$Companion$createDefaultScalarTypeAdapter$adapter$1(function1);
            Map destination$iv$iv = new LinkedHashMap(RangesKt.coerceAtLeast(MapsKt.mapCapacity(classNames.length), 16));
            for (String str : classNames) {
                Pair pair = TuplesKt.to(str, adapter);
                destination$iv$iv.put(pair.getFirst(), pair.getSecond());
            }
            return destination$iv$iv;
        }
    }
}
